<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            function clone(parent, child) {
                // 这里改用 Object.create 就可以减少组合继承中多进行一次构造的过程
                child.prototype = Object.create(parent.prototype);
                child.prototype.constructor = child;
            }

            function Parent() {
                this.name = 'parent';
                this.play = [1, 2, 3];
            }
            Parent6.prototype.getName = function () {
                return this.name;
            };
            function Child() {
                Parent6.call(this);
                this.friends = 'child';
            }

            clone(Parent, Child);

            Child.prototype.getFriends = function () {
                return this.friends;
            };

            let child = new Child()
            console.log(child); //{friends:"child",name:"parent",play:[1,2,3],__proto__:Parent}
            console.log(child.getName()); // parent
            console.log(child.getFriends()); // child
        </script>
    </body>
</html>
